<!doctype <!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>
    <h1>Class 演示</h1>
    <script>
        // 语法糖的Class定义
        class Person {
            constructor(name, gender) {
                this.name = name;
                this.gender = gender;
            }
            say(){
                return "Hello";
            }
            toString() {
                return `Hello ${'Female'===this.gender?'Ms.':'Mr.'} ${this.name}`;
            }
        }

        function Pet(name, kind) {
            this.name = name;
            this.kind = kind;
        }

        Pet.prototype.toString = function () {
            return `${this.name} says '${'cat' === this.kind?'喵~':'旺！'}`;
        }
        let dj = new Person('Xiang', 'Male');
        console.log(dj.toString());
        console.log(dj.say());

        let pet = new Pet('Mi', 'cat');
        console.log(pet.toString());
        // JS标准用法

    </script>
</body>

</html>